package net.zjitc.controller;

import net.zjitc.pojo.Product;
import net.zjitc.service.ProductService;
import net.zjitc.vo.PageBean;
import net.zjitc.vo.ProductVo;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * @AUTHOR zhj
 * @DATE 2019/4/14 11:08
 */
@Controller
public class ProductController {
    @Autowired
    private ProductService productService;

    @RequestMapping("/productDetail")
    public String findProductById(String id, Model model){
        Product product = productService.findById(id);
        model.addAttribute("p",product);
        return "/client/info.jsp";
    }

    //索引的时候按分页显示

    @RequestMapping("/searchProductsByName")
    public String searchProductByName(ProductVo name, @RequestParam(required = false) Integer currentPage, Model model){

        PageBean<Product> pageBean = productService.serachByNameToPage(name, currentPage, 6);
        model.addAttribute("bean",pageBean);
        return "/client/product_search_list.jsp";
    }
}
